package org.bhavni.merge;

public class merge {

	int  firstArr[] ;
	int  secondArr[] ;
	int  merge[] =new int[10]; 
	

	int[] mergeTech(int  firstArr[] , int  secondArr[]) {
		int i = 0, j = 0, k = 0;
		while(  i < firstArr.length  &&  j < secondArr.length) {

			if(firstArr[i] < secondArr[j]){

				merge[k] = firstArr[i] ;
				i++ ;

			} else{
				merge[k] = secondArr[j] ;
				j++ ;
			}

			k++;


		}


		while( k < firstArr.length + secondArr.length ){
			if(j < secondArr.length){
				merge[k] = secondArr[j] ;
				j++ ;

			}else if(i < firstArr.length){
				merge[k] = firstArr[i] ;
				i++ ;
			}
			k++;



		}
		return merge;
	}
	void printArray(int merge[]){
		for (int i = 0; i < merge.length; i++) {
			System.out.println(merge[i]);

		}
	}

	public static void main(String[] args) {

		int  firstArr[] = {2,4,5,7,19};
		int  secondArr[] = {3,6,8,10,15};
		merge merging = new merge();
		int  merge[] = merging.mergeTech(firstArr, secondArr);
		merging.printArray(merge);
	}

}
